#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
int a[N];
int f[N], g[N];
int x[N], y[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) {
    x[i] = x[i - 1];
    if (!f[a[i]]) x[i]++, f[a[i]] = i;
  }
  per(i, n, 1) {
    y[i] = y[i + 1];
    if (!g[a[i]]) y[i]++, g[a[i]] = i;
  }
  int ans = 0;
  rep(i, 1, n - 1) ans = max(ans, x[i] + y[i + 1]);
  cout << ans;
  return 0;
}